package com.java1412.utils;

import java.io.Serializable;
import java.util.List;

/**
 * @author java1412
 * @since 2025-04-30 13:47
 */
public class PageUtil<T> implements Serializable {
    private Integer currentPageNo = 0;
    private Integer pageSize = ConstantUtil.PAGE_SIZE;
    private Integer totalCount = 0;
    private Integer totalPageCount = 0;
    private List<T> data;

    public PageUtil() {
    }

    public Integer getCurrentPageNo() {
        return currentPageNo;
    }

    public void setCurrentPageNo(Integer currentPageNo) {
        this.currentPageNo = currentPageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        this.setTotalPageCountByTotalCount();
    }

    private void setTotalPageCountByTotalCount() {
        if (this.totalCount == null) {
            this.totalPageCount = 0;
        } else if (this.totalCount % this.pageSize == 0) {
            this.totalPageCount = this.totalCount / this.pageSize;
        } else if (this.totalCount % this.pageSize != 0) {
            this.totalPageCount = this.totalCount / this.pageSize + 1;
        }
    }

    public Integer getTotalPageCount() {
        return totalPageCount;
    }

    private void setTotalPageCount(Integer totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }
}
